﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
using FluentAssertions;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;

namespace DocProcessingWorkFlowScenarios
{
    public static class BrowserUtility
    {
        private const string Key = "browser";

        public static FirefoxDriver Current//expose a current property of selemium webdriver FirefoxDriver class
        {
            get//when you access this property getter, 
            {
                if (!ScenarioContext.Current.ContainsKey(Key)) //we first check that the scenario context does not contain a browser, if it does then we just return it, if it doesnt then we go ahead and create a new one
                {
                    var ie = new FirefoxDriver();
                    ie.Manage().Window.Maximize();

                    ScenarioContext.Current[Key] = ie; // once FirefoxDriver object created then we add it to the scenario context
                }

                return ScenarioContext.Current[Key] as FirefoxDriver;
            }
        }

    }
}
